import pygame

from dialog.tunnel_dialog import TunnelTask1BeginDialog, TunnelTask1EndDialog, TunnelTaskFailDialog
from scene.task.stage_one import BaseTask, TaskStatus

"""
拾取奖品任务类
"""
class TakePrizesTask(BaseTask):
    def __init__(self, xiao_tie, japanese_group, prizes_group, font):
        """
        相关参数初始化
        :param xiao_tie:  小铁类
        :param japanese_group: 日军组
        :param prizes_group: 奖品组
        :param font: 字体类
        """
        pygame.mixer.music.load("./resources/sound/十送红军.mp3")
        pygame.mixer.music.play(-1)
        self.score = 0
        self.xiao_tie = xiao_tie
        self.japanese_group = japanese_group
        self.prizes_group = prizes_group
        self.start_dialog = TunnelTask1BeginDialog(font)
        self.win_dialog = TunnelTask1EndDialog(font)
        self.fail_dialog = TunnelTaskFailDialog(font)
        self.sound = pygame.mixer.Sound('./resources/sound/prizes.mp3')
        super(TakePrizesTask, self).__init__(self.start_dialog,
                                             self.win_dialog,
                                             self.fail_dialog)

    def do_self_task(self, key_down, key_list):
        """
        具体任务内容
        :param key_down:
        :param key_list:
        :return:
        """
        temp_rect = self.xiao_tie.rect
        # 优化角色位置
        self.xiao_tie.rect = pygame.Rect(self.xiao_tie.pos_x + 5,
                                         self.xiao_tie.pos_y + 6,
                                         20, 60)
        # 碰撞检测
        collide_prizes_xiao_tie = pygame.sprite.spritecollide(self.xiao_tie, self.prizes_group, True)
        self.xiao_tie.rect = temp_rect
        if len(collide_prizes_xiao_tie) > 0:
            self.sound.play()
            self.xiao_tie.hp += 50
            self.score += 1
        # 成功条件
        if self.score == 2:
            # 设置下一任务开始时小铁手中的武器数量
            self.xiao_tie.set_count(10)
            self.task_status = TaskStatus.win_dialog
